import Vue from 'vue'
import App from './App.vue'
import router from './router'
import dayjs from 'dayjs'
import  './permissions'
//yinru
import './permissions'
import "@/assets/global.css"
import moment from "moment"
// 引入 element-ui 并使用
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUI)

import { Carousel, Slide } from 'vue-carousel'
Vue.use(Carousel)

// 引入 axios
import axios from 'axios'
Vue.prototype.$http = axios;

Vue.filter('dateFormat', date => {
  return dayjs(date).format('YYYY-MM-DD HH:mm:ss')
})

Vue.prototype.moment = moment
Vue.config.productionTip = false

//请求拦截器
axios.interceptors.request.use(config => {
  const token = sessionStorage.getItem('token');
  if (token) {
    config.headers.token = token;
  }
  return config;
})

axios.defaults.baseURL = "http://172.16.2.51:7777"

// 前置守卫
router.beforeEach((to,from,next)=>{
  //如果用户访问的是登录页面，直接放行 ===比较值和引用
  if(to.path === "/login"){
    //放行
    return next();
  }
  //获取session Storage中保存的token值
  const token = window.sessionStorage.getItem('token');
  //如果token不存在，强制跳转到登录页面
  if(!token){
    return next("/login");
  }
  //如果token存在，直接放行
  next();
})







new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
